# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gsm

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.13
pkgrel=2
pkgdesc="Shared libraries for GSM 06.10 lossy speech compression (mingw-w64)"
arch=('any')
url="http://www.quut.com/gsm/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "yasm")
options=('strip' 'staticlibs')
source=("http://www.quut.com/${_realname}/${_realname}-${pkgver}.tar.gz"
    0001-adapt-makefile-to.mingw.patch
    0002-adapt-config-h-to.mingw.patch
    0003-fix-ln.mingw.patch)
md5sums=('c1ba392ce61dc4aff1c29ea4e92f6df4'
         '7956623dd6ecf75fedbc37acb65ce451'
         '50841d8e3e1d3c345c719748dc8d8786'
         'ccf8c284abfb708c59607dd9f5e92dce')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver%.*}-pl${pkgver##*.}"
  patch -p1 -i ${srcdir}/0001-adapt-makefile-to.mingw.patch
  patch -p1 -i ${srcdir}/0002-adapt-config-h-to.mingw.patch
  patch -p1 -i ${srcdir}/0003-fix-ln.mingw.patch
}

build() {
  cp -r ${srcdir}/${_realname}-${pkgver%.*}-pl${pkgver##*.} ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  # Prepare directories
  install -m755 -d "${pkgdir}${MINGW_PREFIX}"/{bin,lib,include,share/{licenses/${_realname},man/man{1,3}}}

  make -j1 INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" \
    install

  # Install license
  install -m644 COPYRIGHT ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/license.txt
}
